package com.ruoyi.web.controller.wq;

import org.springframework.security.access.prepost.PreAuthorize;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wq.domain.WqMiniGame;
import com.ruoyi.wq.service.IWqMiniGameService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信小游戏Controller
 * 
 * @author ruoyi
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/wq/miniGame")
public class WqMiniGameController extends BaseController {

    @Autowired
    private IWqMiniGameService wqMiniGameService;

    /**
     * 查询微信小游戏列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(WqMiniGame wqMiniGame){
    	TableDataInfo info = wqMiniGameService.getPageList(wqMiniGame);
        return info;
    }

    /**
     * 查询游戏二维码
     */
    @Anonymous
    @GetMapping("/getQrCode")
    public R getQrCode(WqMiniGame wqMiniGame) {
    	List<String> data = wqMiniGameService.getQrCode(wqMiniGame.getId());
        return R.ok(data);
    }
    
    /**
     * 查询游戏二维码
     */
    @Anonymous
    @GetMapping("/getAppId")
    public R getAppId(WqMiniGame wqMiniGame) {
    	Map<String,Object> map = new HashMap<>();
    	String appId = wqMiniGameService.getAppId(wqMiniGame.getId());
    	List<String> img = wqMiniGameService.getQrCode(wqMiniGame.getId());
    	map.put("appId", appId);
    	map.put("img", img);
        return R.ok(map);
    }

    /**
     * 新增微信小游戏
     */
    @PreAuthorize("@ss.hasPermi('wq:miniGame:add')")
    @Log(title = "微信小游戏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WqMiniGame wqMiniGame)
    {
        return toAjax(wqMiniGameService.insertWqMiniGame(wqMiniGame));
    }

    /**
     * 修改微信小游戏
     */
    @PreAuthorize("@ss.hasPermi('wq:miniGame:edit')")
    @Log(title = "微信小游戏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WqMiniGame wqMiniGame)
    {
        return toAjax(wqMiniGameService.updateWqMiniGame(wqMiniGame));
    }

    /**
     * 删除微信小游戏
     */
    @PreAuthorize("@ss.hasPermi('wq:miniGame:remove')")
    @Log(title = "微信小游戏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wqMiniGameService.deleteWqMiniGameByIds(ids));
    }
}
